/*
 * Copyright (C) 2006-2007 Eskil Bylund
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

using System;

using Gtk;

namespace DCSharp.Gui
{
	public abstract class Page : VBox
	{
		public event EventHandler PageChanged;
		public event EventHandler StatusChanged;

		private string status = String.Empty;
		private bool isWorking;

		#region Constructors

		protected Page(string resource) : this()
		{
			using (Glade.XML xml = new Glade.XML (null, Util.GetResource(resource),
				"page", null))
			{
				xml.BindFields(this);
				PackEnd(xml.GetWidget("page"));
			}
		}

		protected Page() : base()
		{
			BorderWidth = 6;
			Spacing = 6;
		}

		#endregion

		#region Properties

		public abstract string Title
		{
			get;
		}

		public abstract Gdk.Pixbuf Icon
		{
			get;
		}

		public abstract string Tooltip
		{
			get;
		}

		public virtual string Status
		{
			get { return status; }
			protected set
			{
				status = value;
				OnStatusChanged();
			}
		}

		public virtual bool IsWorking
		{
			get { return isWorking; }
			protected set
			{
				if (value != isWorking)
				{
					isWorking = value;

					OnStatusChanged();
					OnPageChanged();
				}
			}
		}

		public virtual ActionGroup Actions
		{
			get { return null; }
		}

		public virtual string UI
		{
			get { return null; }
		}

		#endregion

		#region Methods

		protected void Add(MessageArea dialog)
		{
			PackStart(dialog, false, false, 0);
		}

		protected void OnPageChanged()
		{
			if (PageChanged != null)
			{
				PageChanged(this, EventArgs.Empty);
			}
		}

		protected void OnStatusChanged()
		{
			if (StatusChanged != null)
			{
				StatusChanged(this, EventArgs.Empty);
			}
		}

		#endregion
	}	
}
